<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Collection
 *
 * @author ketu
 */
class Zhishidi_Express_Model_Mysql4_Zone_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract {

    protected function _construct() {
        $this->_init('zhishidi_express/zone');
    }

    public function joinZoneConfig() {
        $this->getSelect()->joinLeft(
                array('_table_zone_config' => $this->getTable('zhishidi_express/shipping_zone_config')),
                '(_table_zone_config.zone_id = main_table.zone_id) ',
                array('zone_price' => '_table_zone_config.zone_price', 'zone_unit' => '_table_zone_config.zone_unit')
        );
        return $this;
    }

    public function joinZoneType() {
        $this->getSelect()->join(
                array('_table_type' => $this->getTable('zhishidi_express/shipping_type')),
                '(_table_type.type_id = main_table.zone_type)',
                array('type_name' => '_table_type.type_name', 'type_code' => '_table_type.type_code')
        );
        return $this;
    }

    public function joinZoneGroup() {
        $this->getSelect()->joinLeft(
                array('_table_group' => $this->getTable('zhishidi_express/shipping_zone_group')),
                '(main_table.zone_group = _table_group.group_id)',
                array('group_name' => '_table_group.group_name')
        );

        return $this;
    }

    public function addTypeFilter($type) {
        $this->getSelect()->where('main_table.zone_type = ?', (int) $type);
        return $this;
    }

    public function addVisibleFilter($visible = 'public') {
        $this->getSelect()->where('main_table.zone_status = ?', $visible);
        return $this;
    }

}

?>
